package com.ihr360.payroll.service.eventhandler;

import com.ihr360.commons.lang.CollectionUtils;
import com.ihr360.event.annonation.RestEventListener;
import com.ihr360.payroll.model.dto.salary.plan.SalaryPlan;
import com.ihr360.payroll.service.salaryplan.SalaryPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author tomtao
 */
@Component
public class SalaryPlanRestEventListener implements RestEventListener<SalaryPlan, Long> {

    @Autowired
    private SalaryPlanService service;

    @Override
    public void beforeCreate(SalaryPlan salaryPlan) {
        salaryPlan.setSystemTemplate(false);
    }



    @Override
    public SalaryPlan afterCreateOrUpdate(SalaryPlan salaryPlan) {
        //添加默认工资单
        if (CollectionUtils.isEmpty(salaryPlan.getPayslipConfigs())) {
            service.createDefaultPayslipConfig(salaryPlan.getId());
        }
        return salaryPlan;
    }
}
